#! /usr/bin/env python

'''
This code was developed by the National Robotics Engineering Center (NREC),
part of Carnegie Mellon University's Robotics Institute.  Its development was
funded by DARPA under the LS3 program and submitted for public release
on June 7th, 2012.  Release was granted on August, 21st 2012 with Distribution Statement A
(Approved for Public Release, Distribution Unlimited).

This software is released under a BSD license:

Copyright (c) 2012, National Robotics Engineering Center (NREC)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the National Robotics Engineering Center (NREC) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''

'''
   @file Camera.cfg
   @author Chad Rockey
   @date July 11, 2011
   @brief Interface to Point Grey cameras

   @attention Copyright (C) 2011
   @attention National Robotics Engineering Center
   @attention Carnegie Mellon University
   @attention Adapted from ROS Camera1394.cfg by Jack O' Quin
'''

#*  Copyright (c) 2010, Jack O'Quin
#*  All rights reserved.  BSD.
#*
#*  Redistribution and use in source and binary forms, with or without
#*  modification, are permitted provided that the following conditions
#*  are met:
#*
#*   * Redistributions of source code must retain the above copyright
#*     notice, this list of conditions and the following disclaimer.
#*   * Redistributions in binary form must reproduce the above
#*     copyright notice, this list of conditions and the following
#*     disclaimer in the documentation and/or other materials provided
#*     with the distribution.
#*   * Neither the name of the author nor the names of other
#*     contributors may be used to endorse or promote products derived
#*     from this software without specific prior written permission.
#*
#*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
#*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
#*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
#*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#*  POSSIBILITY OF SUCH DAMAGE.
#***********************************************************

PACKAGE='pointgrey_camera_driver'

from dynamic_reconfigure.parameter_generator_catkin import *

class SensorLevels:
  RECONFIGURE_RUNNING = 0
  RECONFIGURE_STOP = 1

gen = ParameterGenerator()
#       Name                    Type      Reconfiguration level             Description                                                                                      Default    Min   Max

video_modes = gen.enum([gen.const("Format0_Mode5", str_t, "640x480_mono8", ""),
                  gen.const("Format0_Mode6", str_t, "640x480_mono16", ""),
                  gen.const("Format2_Mode1", str_t, "1280x960_bayer8", ""),
                  gen.const("Format2_Mode2", str_t, "1280x960_mono8", ""),
                  gen.const("Format2_Mode6", str_t, "1280x960_mono16", ""),
                  gen.const("Format7_Mode0", str_t, "format7_mode0", ""),
                  gen.const("Format7_Mode1", str_t, "format7_mode1", ""),
                  gen.const("Format7_Mode2", str_t, "format7_mode2", ""),
                  gen.const("Format7_Mode3", str_t, "format7_mode3", ""),
                  gen.const("Format7_Mode4", str_t, "format7_mode4", ""),
                  gen.const("Format7_Mode5", str_t, "format7_mode5", ""),
                  gen.const("Format7_Mode7", str_t, "format7_mode7", ""),
                  ],
                 "Video mode for camera.")

gen.add("video_mode", 	      str_t,    SensorLevels.RECONFIGURE_STOP,       "Video mode.",                                                                                "format7_mode0", edit_method = video_modes)

gen.add("frame_rate",         double_t, SensorLevels.RECONFIGURE_RUNNING,    "Camera speed (frames per second).",				                             7, 0, 100)

gen.add("auto_exposure",      bool_t,   SensorLevels.RECONFIGURE_RUNNING,    "Allow the camera to automatically change exposure (Combined Gain, Iris & Shutter control).",  True)
gen.add("exposure",           double_t, SensorLevels.RECONFIGURE_RUNNING,         "Auto exposure value (like contrast).",				                             1.35, -10.0, 10.0)

gen.add("auto_shutter",       bool_t,   SensorLevels.RECONFIGURE_RUNNING,     "Shutter control state.",				            		                     True)
gen.add("shutter_speed",      double_t, SensorLevels.RECONFIGURE_RUNNING,     "Amount of time (in seconds) for the apeture to remain open.",				     0.03, 0.0, 1.0)

gen.add("auto_gain",          bool_t,   SensorLevels.RECONFIGURE_RUNNING,     "Gain control state.",				                                             True)
gen.add("gain",               double_t, SensorLevels.RECONFIGURE_RUNNING,     "Relative circuit gain.",				                                             0, -10, 30)

gen.add("pan",                int_t, 	SensorLevels.RECONFIGURE_RUNNING,     "Controls camera pan.",				                                             0, -1000, 1000)

gen.add("tilt",               int_t, 	SensorLevels.RECONFIGURE_RUNNING,     "Controls camera tilt.",				                                             0, -1000, 1000)


gen.add("brightness",         double_t, SensorLevels.RECONFIGURE_RUNNING,     "Black level offset.",				                                             0.0, 0.0, 10.0)

gen.add("auto_sharpness",      bool_t,   SensorLevels.RECONFIGURE_RUNNING,    "Allow the camera to automatically change sharpness.",  True)
gen.add("sharpness",         double_t, SensorLevels.RECONFIGURE_RUNNING,     "sharpness.",				                                             1024.0, 0.0, 4095.0)

gen.add("auto_saturation",      bool_t,   SensorLevels.RECONFIGURE_RUNNING,    "Allow the camera to automatically change saturation.",  True)
gen.add("saturation",         double_t, SensorLevels.RECONFIGURE_RUNNING,     "saturation.",				                                              100.0, 0.0, 399.0)

gen.add("gamma",              double_t, SensorLevels.RECONFIGURE_RUNNING,     "Gamma expansion exponent.",				             		             1.0, 0.5, 4.0)

gen.add("auto_white_balance", bool_t,    SensorLevels.RECONFIGURE_RUNNING,     "Automatically change white balance", True)

gen.add("white_balance_blue", int_t,    SensorLevels.RECONFIGURE_RUNNING,     "White balance blue component.",				             		             800, 0, 1023)

gen.add("white_balance_red",  int_t,    SensorLevels.RECONFIGURE_RUNNING,     "White balance red component.",				             		             550, 0, 1023)

# Format7-specific parameters
gen.add("format7_roi_width", int_t, SensorLevels.RECONFIGURE_STOP,         "Width of Format7 Region of Interest in unbinned pixels, full width if zero.",                 0, 0, 65535)

gen.add("format7_roi_height", int_t, SensorLevels.RECONFIGURE_STOP,        "Height of Format7 Region of Interest in unbinned pixels, full height if zero.",               0, 0, 65535)

gen.add("format7_x_offset", int_t, SensorLevels.RECONFIGURE_STOP,          "Horizontal offset for left side of Format7 ROI in unbinned pixels.",                          0, 0, 65535)

gen.add("format7_y_offset", int_t, SensorLevels.RECONFIGURE_STOP,          "Vertical offset for top of Format7 ROI in unbinned pixels.",                                  0, 0, 65535)

codings = gen.enum([gen.const("Mono8", str_t, "mono8", ""),
                    gen.const("Mono16", str_t, "mono16", ""),
                    gen.const("Raw8", str_t, "raw8", ""),
                    gen.const("Raw16", str_t, "raw16", ""),
                    gen.const("RGB8", str_t, "rgb8", "")],
                    "Format7 color coding methods")

gen.add("format7_color_coding", str_t, SensorLevels.RECONFIGURE_STOP,      "Color coding (only for Format7 modes)",                                                       "raw8",      edit_method = codings)

# Trigger parameters
gen.add("enable_trigger",       bool_t,   SensorLevels.RECONFIGURE_RUNNING,   "Enable the external triggering mode.",                                                        False)

trigger_modes = gen.enum([gen.const("Mode0", str_t, "mode0", ""),
                    gen.const("Mode1_bulb_trigger", str_t, "mode1", ""),
                    gen.const("Mode3", str_t, "mode3", ""),
                    gen.const("Mode14", str_t, "mode14", "")],
                    "IIDC v1.31 Trigger Modes")

gen.add("trigger_mode", str_t, SensorLevels.RECONFIGURE_RUNNING,              "IIDC v1.31 Trigger Modes",                                                                    "mode0",     edit_method = trigger_modes)

gpio_pins = gen.enum([gen.const("GPIO0", str_t, "gpio0", ""),
                    gen.const("GPIO1", str_t, "gpio1", ""),
                    gen.const("GPIO2", str_t, "gpio2", ""),
                    gen.const("GPIO3", str_t, "gpio3", "")],
                    "GPIO Trigger Sources")

gen.add("trigger_source", str_t, SensorLevels.RECONFIGURE_RUNNING, "GPIO Trigger Sources",                                                                                   "gpio0",     edit_method = gpio_pins)

polarities = gen.enum([gen.const("Low", int_t, 0, "Low Polarity"),
                    gen.const("High", int_t, 1, "High Polarity")],
                    "GPIO Polarities")

gen.add("trigger_polarity", int_t, SensorLevels.RECONFIGURE_RUNNING, "GPIO Trigger Polarity", 0, edit_method = polarities)

gen.add("enable_trigger_delay",       bool_t,   SensorLevels.RECONFIGURE_RUNNING,    "Whether Trigger Delay is active.",                      				     False)

gen.add("trigger_delay",              double_t, SensorLevels.RECONFIGURE_RUNNING,    "The trigger delay to wait once triggered (in seconds).",				     0.0, 0.0, 1.0)

gen.add("trigger_parameter", 	      int_t,    SensorLevels.RECONFIGURE_RUNNING,    "Trigger mode parameter.  Varies based on mode.",                                      0, -32768, 32767)

gen.add("enable_strobe1", bool_t, SensorLevels.RECONFIGURE_RUNNING, "Whether strobe is sent.", False)

gen.add("strobe1_polarity", int_t, SensorLevels.RECONFIGURE_RUNNING, "GPIO Strobe Polarity", 0, edit_method = polarities)

gen.add("strobe1_delay", double_t, SensorLevels.RECONFIGURE_RUNNING, "The delay between capture and strobe out (in milliseconds).", 0.0, 0.0, 1000.0)

gen.add("strobe1_duration", double_t, SensorLevels.RECONFIGURE_RUNNING, "Strobe duration (in milliseconds)", 0.0, 0.0, 1000.0)

gen.add("enable_strobe2", bool_t, SensorLevels.RECONFIGURE_RUNNING, "Whether strobe is sent.", False)

gen.add("strobe2_polarity", int_t, SensorLevels.RECONFIGURE_RUNNING, "GPIO Strobe Polarity", 0, edit_method = polarities)

gen.add("strobe2_delay", double_t, SensorLevels.RECONFIGURE_RUNNING, "The delay between capture and strobe out (in milliseconds).", 0.0, 0.0, 1000.0)

gen.add("strobe2_duration", double_t, SensorLevels.RECONFIGURE_RUNNING, "Strobe duration (in milliseconds)", 0.0, 0.0, 1000.0)


exit(gen.generate(PACKAGE, "pointgrey_camera_driver", "PointGrey"))
